﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DeepTalkWF;
using IndicoInterface;
using IndicoInterface.SimpleAgendaDataModel;
using System.IO;

namespace DeepTalkWFTest
{
    /// <summary>
    /// Test out the WF item called GetAgenda.
    /// </summary>
    [TestClass]
    public class t_GetAgenda
    {
        public t_GetAgenda()
        {
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestSimpleAgendaDownload()
        {
            AgendaInfo info = new AgendaInfo("http://agenda.hep.wisc.edu/conferenceOtherViews.py?view=standard&confId=60");

            var results = Utilities.RunWFByType(typeof(GetAgenda),
                new Dictionary<string, object> { { "AgendaXML", Utilities.AgendaAsXML(info) } }
                );

            Assert.IsTrue(results != null, "The results should not have been null on the way back!");
            Assert.IsTrue(results.ContainsKey("Title"), "Missing the title");
            Assert.IsTrue(results.ContainsKey("MeetingInfo"), "Missing the meeting info from the download!");
            Assert.IsTrue(results.ContainsKey("StartTime"), "Missing the meeting start time");
            Assert.IsTrue(results["Title"] as string == "Pheno 2008 Symposium", "Agenda title is not correct");
            Assert.IsTrue((DateTime) results["StartTime"] == new DateTime(2008, 4, 28, 0, 30, 0), "The start time is incorrect");
            Meeting m = results["MeetingInfo"] as Meeting;
            Assert.IsTrue(m.Title == "Pheno 2008 Symposium", "Agenda title isn't right in the meeting info guy!");
        }

        [TestMethod]
        public void TestSimpleAgendaDownloadWPers()
        {
            AgendaInfo info = new AgendaInfo("http://agenda.hep.wisc.edu/conferenceOtherViews.py?view=standard&confId=60");

            var results = Utilities.RunWFByTypeWPers(typeof(GetAgenda),
                new Dictionary<string, object> { { "AgendaXML", Utilities.AgendaAsXML(info) } },
                new DirectoryInfo (".\\TestSimpleAgendaDownloadWPers")
                );
            Assert.IsTrue(results != null, "Results came back null!");
            Assert.IsTrue(results.ContainsKey("Title"), "Title is missing");
            Assert.IsTrue((string)results["Title"] == "Pheno 2008 Symposium", "Title is incorrect");
        }
    }
}
